package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.query.DestinationQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Controller
@RequestMapping("destination")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;



    //页面数据和分页
    @RequestMapping("/list")
    public String List(Model model, @ModelAttribute("qo") DestinationQuery qo) {
        //查询关键字和页面
        Page<Destination> page = destinationService.query(qo);
        model.addAttribute("page", page);
        //查询吐司
        List toasts = destinationService.queryToasts(qo.getParentId());
        model.addAttribute("toasts",toasts);
        return "destination/list";
    }



    //删除
    @GetMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        destinationService.delete(id);
        return JsonResult.success();
    }
}
